/*
 * @Author: fisher
 * @Date: 2024-02-23 11:52:10
 * @LastEditors: luthor luthor-li@qq.com
 * @LastEditTime: 2024-03-08 21:51:30
 * @FilePath: \allback\models\ueinstanceModel.js
 * @Description:
 */
const mongoose = require('mongoose')
const dayjs = require('dayjs')

const connectionSchema = new mongoose.Schema({
  userId: {
    type: String,
    required: true
  },
  playerId: {
    type: String,
    required: true
  },
  clientIp: {
    type: String,
    required: true
  },
  signalHost: {
    type: String,
    required: true
  },
  signalPort: {
    type: Number,
    required: true
  },
  useHttps: {
    type: Boolean,
    default: false
  },
  uploadDate: {
    type: String,
    default: dayjs().format('YYYY-MM-DD HH:mm:ss')
  }
})
const ueinstanceSchema = new mongoose.Schema(
  {
    instanceIp: {
      type: String,
      required: true
    },
    name: { type: String, required: true, unique: true },
    useHttps: { type: Boolean, default: false },
    port: { type: Number, require: true, default: 81, unique: true },
    projectId: { type: String, required: true },
    projectName: { type: String, required: true },
    runStatus: { type: Boolean, default: false },
    runTimestamp: { type: Number, default: 0 },
    totalRuntimes: { type: Number, default: 0 },
    connectStatus: { type: Boolean, default: false },
    connections: [connectionSchema],
    useRelay: { type: Boolean, default: false },
    stun: { type: String },
    turn: { type: String },
    relayUsername: { type: String },
    relayPassword: { type: String },
    httpsCertFile: { type: String },
    httpsKeyFile: { type: String },
    uploadDate: {
      type: String,
      default: dayjs().format('YYYY-MM-DD HH:mm:ss')
    }
  },
  {
    timestamps: true // 开启自动生成时间戳
  }
)

module.exports = mongoose.model('Ueinstance', ueinstanceSchema)
